<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
	<th:block th:include="include :: header('泵站详情')" />
</head>
<body>
    <div class="container-div">
    <input name="stationId" autocomplete="off" id="psId"  class="form-control" type="hidden" th:value="${pumpStationInfo.id}" >
    	<div class="row">
    		 <div th:include="biz/pumpStation/include::detail-header"></div> 
    		<div class="col-sm-12">
		    	<div class="btn-group-sm" id="toolbar" role="group">
					 <a class="btn btn-success" onclick="addElement()" shiro:hasPermission="biz:se:add">
						<i class="fa fa-plus"></i> 添加组件
					</a> 
				</div>
				<table id="element-table" data-mobile-responsive="true"></table>
    		</div>
    	</div>
	</div>
    <div th:include="include::footer"></div>
    <script th:inline="javascript">
	    var editFlag = [[${@permission.hasPermi('biz:se:edit')}]];
	    var removeFlag = [[${@permission.hasPermi('biz:se:remove')}]];
	    var types = [[${@dict.getType('biz_is_valid')}]];
	    var seTypes = [[${@dict.getType('biz_se_type')}]];
	    var isOpens = [[${@dict.getType('biz_is_open')}]];
	    var prefix = ctx + "biz/stationElement";
        
        function addElement(){
        	var url = prefix + "/add?stationId="+[[${pumpStationInfo.id}]]+"&stationName="+[[${pumpStationInfo.name}]];
        	$.modal.open('添加组件', url);
        }
        
        
        $(function() {
            var options = {
            	id: "element-table",
                url: prefix + "/detailList?stationId="+[[${pumpStationInfo.id}]],
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "泵站组件",
                columns: [
				{
					field : 'id', 
					title : '组件ID' 
				},
				{
					field : 'type', 
					title : '组件类型',
					align: 'center',
			        formatter: function(value, row, index) {
			        	var typeValue="";
			        	switch(row.type){
			        	case"0":
			        		typeValue="阀门";
			        		break;
			        	case"2":
			        		typeValue="水库泵";
			        		break;
			        	case"3":
			        		typeValue="增压泵";
			        		break;
			        	default:
			        		typeValue="水库";
			        	}
			        	//return $.table.selectDictLabel(seTypes, value);
			        	return typeValue;
			        }
				},
				{
					field : 'serialNumber', 
					title : '组件编号' 
				},
				{
					field : 'stationName', 
					title : '泵站名称' 
				},
				{
		            field: 'isOpen',
		            title: '阀门状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var isOpen = '';
		            	switch(row.isOpen){
		            	case '0':
		            		isOpen='阀门关闭';
		            		break;
		            	default:
		            		isOpen='阀门已开';
		            	}
		            	return isOpen;
		            }
		        }, 
				{
		            field: 'isValid',
		            title: '是否有效',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return statusTools(row);
		            }
		        },
				
				{
					field : 'createBy', 
					title : '创建者' 
				},
				{
		            field: 'createTime',
		            title: '创建时间',
		            sortable: false
		        },
		         {
					field : 'updateBy', 
					title : '更新者' 
				},
				{
		            field: 'updateTime',
		            title: '更新时间',
		            sortable: false
		        }, 
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        
		function statusTools(row) {
		    if (row.isValid == 0) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
    		}
		}
		
		function disable(id) {
			$.modal.confirm("确认要停用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 0 });
		    })
		}

		function enable(id) {
			$.modal.confirm("确认要启用吗？", function() {
				$.operate.post(prefix + "/changeStatus", { "id": id, "status": 1 });
		    })
		}
         
      
    </script>
</body>
</html>
